package com.miao.manage.web.controller;


import org.springframework.ui.Model;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.miao.entity.TbUser;
import com.miao.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author shuangshuang
 * @since 2018-09-07
 */
@Controller
@RequestMapping("/tbUser")
public class TbUserController {
    @Autowired
    private TbUserService tbUserService;

//    @ResponseBody
//    @RequestMapping("/queryUsers")
//    public Page<TbUser> queryUsers(@RequestParam(defaultValue = "1") Integer pageNum){
//        Page<TbUser> page = new Page<>(pageNum,3);
//        EntityWrapper<TbUser> wrapper = new EntityWrapper<>();
//        Page<TbUser> tbUserPage = tbUserService.selectPage(page,wrapper);
//        return  tbUserPage;
//    }

    /**
     * 登录
     * @return
     */
    @ResponseBody
    @RequestMapping("/query")
    public  TbUser query(String username, String password, Model model){
        TbUser tbUser= new TbUser();
        try{
            EntityWrapper<TbUser> wrapper = new EntityWrapper<>();
            wrapper.where("username={0}",username).and("password={0}",password);
            tbUser = tbUserService.selectOne(wrapper);
            if(tbUser==null||"".equals(tbUser)){
                throw new RuntimeException("用户名或密码错误！");
            }
        }catch (Exception e){
            e.getMessage();
        }
        return tbUser;

    }

}

